<?php


namespace App\Customer\Controller;

use App\Customer\Model\CaseModel;
use EchoPHP\Http\Request;
use App\Service\ExternalAPI\EhireApi;
use App\Web\Model\EhireUser as UserModel;

class Login extends BaseController {

    /**登录接口
     * @param Request $request
     * @return \EchoPHP\Http\Response\JsonResponse
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function login(Request $request) {
        $memberName = $request->getPost('membername', '');
        $userName = $request->getPost('username', '');
        $passWord = $request->getPost('password', '');
        $allowmultilogin = 1; //允许多点登陆
        /*
        $memberName = '51jobsh石雷';
        $userName = 'guoziheng';
        $passWord = 'abc123!!';
        */

        $userModel = new UserModel();
        $resultBody = $userModel->login($memberName, $userName, $passWord, $allowmultilogin);

        //echo "<pre/>";
        //var_dump($resultBody['data']);
        //$url = "http://10.100.50.67:1983/User/getRecommendList?authToken=" . $resultBody['data']['authToken'];
        //echo "<a href='" . $url . "' target='_blank'>打开</a>";
        //exit();

        return $this->json(
            $resultBody
        );
    }

    /**
     * 找回密码URL
     * @param Request $request
     * @return \EchoPHP\Http\Response\JsonResponse
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function findPasswordUrl(Request $request) {
        $ehireApi = new EhireApi();
        $resultBody = $ehireApi->ehireFindPasswordUrl();
        return $this->json(
            $resultBody
        );
    }

    /**
     * 获取非对称加密公钥
     * @return \EchoPHP\Http\Response\JsonResponse
     * @throws \Exception
     */
    public function publickey() {
        $publicKey = file_get_contents(config('app.jwt.public_key'));
        return $this->json(['status' => true, 'message' => '操作成功', 'publicKey' => $publicKey]);
    }

    /**测试接口  http://10.100.50.67:1983/Login/test
     * @param Request $request
     * @return \EchoPHP\Http\Response\JsonResponse
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function test(Request $request) {
        $ehireApi = new EhireApi();
        echo "<pre/>";
        $this->domain = '';
        $this->host = 'http://10.100.50.67:1982';
        $requestPath = '/Api/addsuperusercallback';
        $getData = [];
        $postData = array(
            'ctmid' => 778899,
            'membername' => '郭子恒的点点滴滴',
            'hruid' => 1122333,
        );
        $content = $ehireApi->requestTest($requestPath, 'POST', $getData, $postData);
    }


}